package com.ev.scm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.ev.scm.dao.CostAdjustmentItemDao;
import com.ev.scm.domain.CostAdjustmentItemDO;
import com.ev.scm.service.CostAdjustmentItemService;
import com.ev.scm.vo.CostAdjustmentItemPageParam;
import com.ev.framework.utils.R;
import com.ev.apis.model.DsResultResponse;
import com.google.common.collect.Maps;


@Service
public class CostAdjustmentItemServiceImpl implements CostAdjustmentItemService {
    @Autowired
    private CostAdjustmentItemDao costAdjustmentItemDao;

    @Override
    public CostAdjustmentItemDO get(Long id) {
        return costAdjustmentItemDao.get(id);
    }

    @Override
    public List<CostAdjustmentItemDO> list(Map<String, Object> map) {
        return costAdjustmentItemDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return costAdjustmentItemDao.count(map);
    }

    @Override
    public int save(CostAdjustmentItemDO costAdjustmentItem) {
        return costAdjustmentItemDao.save(costAdjustmentItem);
    }

    @Override
    public int update(CostAdjustmentItemDO costAdjustmentItem) {
        return costAdjustmentItemDao.update(costAdjustmentItem);
    }

    @Override
    public int updateAll(CostAdjustmentItemDO costAdjustmentItem) {
        return costAdjustmentItemDao.updateAll(costAdjustmentItem);
    }

    @Override
    public int remove(Long id) {
        return costAdjustmentItemDao.remove(id);
    }

    @Override
    public int batchRemove(Long[] ids) {
        return costAdjustmentItemDao.batchRemove(ids);
    }

    @Override
    public R saveAndVerify(CostAdjustmentItemDO saveParam) {
        if (saveParam.getId() != null) {
            return costAdjustmentItemDao.update(saveParam) > 0 ? R.ok() : R.error();
        }
        return costAdjustmentItemDao.save(saveParam) > 0 ? R.ok() : R.error();
    }

    @Override
    public Map<String, Object> getById(Long id) {
        CostAdjustmentItemDO costAdjustmentItem = costAdjustmentItemDao.get(id);
        Map<String, Object> result = Maps.newHashMap();
        if (costAdjustmentItem !=null){
            result.put("data",costAdjustmentItem);
            return result;
        }
        return result;
    }

    @Override
    public Map<String, Object> pageList(CostAdjustmentItemPageParam pageParam) {
        Map<String, Object> result = Maps.newHashMap();
        List<Map<String, Object>> data = costAdjustmentItemDao.pageList(pageParam);
        if (data.size() > 0) {
            int total = costAdjustmentItemDao.pageCount(pageParam);
            result.put("data", new DsResultResponse(pageParam.getPageno(), pageParam.getPagesize(), total, data));
        }
        return result;
    }

}
